package com.southsmart.springboot.email.controller;

import com.southsmart.springboot.email.service.IEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author : CaoLongMin
 * @version 1.0
 * @since 2021/4/26
 */
@RequestMapping("/email")
@RestController
public class EmailController {


    @Autowired
    private IEmailService iEmailService;
    /**
     * 发送简单邮件
     * @param msg
     * @param email
     * @return
     */
    @PostMapping(value = "/sendSimpleEmail")
    public String sendSimpleEmail(String msg, String email) {


        if (StringUtils.isEmpty(msg) || StringUtils.isEmpty(email)) {
            return "请输入要发送消息和目标邮箱";
        }
        return iEmailService.sendSimpleEmail(msg,email);

    }

    /**
     * 发送html邮件
     * @param msg
     * @param email
     * @return
     */
    @PostMapping(value = "/sendHtmlMsg")
    public String sendHtmlMsg(String msg, String email) {
        if (StringUtils.isEmpty(msg) || StringUtils.isEmpty(email)) {
            return "请输入要发送消息和目标邮箱";
        }
        return iEmailService.sendHtmlMsg(msg,email);

    }

    /**
     * 发送带文件邮件
     * @param msg
     * @param email
     * @return
     */
    @PostMapping(value = "/sendFileEmail")
    public String sendFileEmail(String msg, String email) {
        if (StringUtils.isEmpty(msg) || StringUtils.isEmpty(email)) {
            return "请输入要发送消息和目标邮箱";
        }
        return iEmailService.sendFileEmail(msg,email);

    }

    /**
     * 发送带图片的邮件
     * @param msg
     * @param email
     * @return
     */
    @PostMapping(value = "/sendImgEmail")
    public String sendImgEmail(String msg, String email) {
        if (StringUtils.isEmpty(msg) || StringUtils.isEmpty(email)) {
            return "请输入要发送消息和目标邮箱";
        }
        return iEmailService.sendImgEmail(msg,email);

    }
}
